package com.io;

import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.nio.charset.StandardCharsets;

/**
 * @author: csh
 * @Date: 2022/5/31 23:06
 * @Description:
 */
public class BioClient {
    //服务器端口
    private static int SERVER_PORT= 8080;
    //服务器ip
    private static String SERVER_IP = "127.0.0.1";

    public static void main(String[] args) {
        Socket socket = null;
        InputStream in =null;
        OutputStream out = null;
        try {
            socket = new Socket(SERVER_IP,SERVER_PORT);
            OutputStream outputStream = socket.getOutputStream();
            byte[] msg = "hello server i'm hong!!".getBytes(StandardCharsets.UTF_8);
            outputStream.write(msg);
            byte[] bytes = new byte[1024];
            in = socket.getInputStream();
            in.read(bytes);
            System.out.println("服务端返回数据："+new String(bytes));


        }catch (Exception e){
            e.printStackTrace();
        }finally {
            if(in!=null){
                try {
                    in.close();
                }catch (Exception e){
                    e.printStackTrace();
                }
                in = null;
            }
        }
    }
}
